package com.xy.farm.activity.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by 1174607250 on 2018/6/30.
 */

public class PageAdapter extends PagerAdapter
{
    private List<View> views = new ArrayList<>();
    private List<String> titles = new ArrayList<>();

    public PageAdapter(List<View> views, List<String> titles)
    {
        this.views = views;
        this.titles = titles;
    }
    public PageAdapter(List<View> views, String... titles)
    {
        this.views = views;
        Collections.addAll(this.titles, titles);
    }
    @Override
    public int getCount()
    {
        return views.size();
    }
    @Override
    public CharSequence getPageTitle(int position)
    {
        return titles.get(position);
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object)
    {
        container.removeView((View) object);
    }
    @Override
    public boolean isViewFromObject(View view, Object object)
    {
        return view == object;
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position)
    {
        container.addView(views.get(position));
        return views.get(position);
    }
}
